<?php
namespace Admin\Controller;
use Common\Controller\AdminController;

class ProductController extends AdminController{
	public function index(){
		if(IS_POST){
			$_POST['times'] = time();
            $result = $this->updateData($_POST, 'product');
		    $this->returnResult($result);
		}else{
			$where = '1=1';
			$where .= $_GET['cid'] ? ' and cid=' . $_GET['cid'] : '';
			$where .= $_GET['name'] ? ' and name like "%' . $_GET['name'] . '%"' : '';
			$list = $this->getList('*', 'product', $where, 'id desc', true, 15);
			$this->assign('list', $list);
			$list_sto = $this->getList('*', 'Storehouse', null, 'id asc', true, 15);
			$this->assign('list_sto', $list_sto);
			$list_cke = $this->getList('id,name', 'cangku', null, 'id asc', true);
			$this->assign('list_cke', $list_cke);
			$this->display();
		}
		
	}
  public function edit(){
		if(IS_POST){
			$result = $this->updateData($_POST, 'product',2);
			$this->returnResult($result);
		}else{
			$info = $this->getInfo('*', 'product', array('id' => I('get.id', 0, 'intval')));
			$list_sto = $this->getList('*', 'Storehouse', null, 'id asc', true, 15);
			$this->assign('list_sto', $list_sto);
			$list_cke = $this->getList('id,name', 'cangku', null, 'id desc', true);
			$this->assign('list_cke', $list_cke);
			if($info){
				$data['info'] = $info;
				$data['status'] = 1;
			}else{
				$data['info'] = '数据不存在';
				$data['status'] = 0;
			}
			$this->ajaxReturn($data);
			
		}
	}

	
	public function del(){
		$result = $this->deleteData('id=' . $_GET['id'], 'Product');
		$this->returnResult($result);
	}

	
}